import { reqTrade, reqUserAddress } from "@/api";

export default {
  actions: {
    // 获取用户地址信息
    async getUserAddress ({ commit }) {
      let result = await reqUserAddress();
      if (result.code == 200) {
        commit('GETUSERADDRESS', result.data);
        return 'ok';
      } else {
        return Promise.reject(new Error('获取用户地址失败!'));
      }
    },

    // 获取用户订单信息
    async getUserTrade ({ commit }) {
      let result = await reqTrade();
      // console.log(result);
      if (result.code == 200) {
        commit('GETUSERTRADE', result.data);
        return result.message;
      } else {
        return Promise.reject(new Error(result.message));
      }
    }
  },
  mutations: {
    GETUSERADDRESS (state, userAddress) {
      state.userAddress = userAddress;
    },
    GETUSERTRADE (state, userTrade) {
      state.userTrade = userTrade;
    }
  },
  state: {
    // 用户地址信息
    userAddress: [],
    userTrade: {}
  },
  getters: {}
}
